const std = @import("std");

// 温度转换
fn celsiusToFahrenheit(c: f64) f64 {
    return (c * 9.0 / 5.0) + 32.0;
}

fn getUserInput() !f64 {
    const stdin = std.io.getStdIn().reader();
    defer stdin.context.close();

    std.debug.print("输入摄氏度：", .{});
    var buffer: [64]u8 = undefined;
    const input = try stdin.readUntilDelimiter(buffer[0..], '\n');
    return std.fmt.parseFloat(f64, input);
}

// 返回类型为 !void
pub fn run() !void {
    // try 后面无 {}
    const celsius = try getUserInput();
    const fahrenheit = celsiusToFahrenheit(celsius);
    std.debug.print("{d:.2}°C = {d:.2}°F\n", .{ celsius, fahrenheit });
}
